<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"                    
                xmlns:bi="http://java.sun.com/jsf/composite/bill"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">

    <ui:define name="content">
        <h:panelGroup >
            <h:form  >
                <p:panel rendered="#{!cashRecieveBillController.printPreview}" >
                    <f:facet name="header" >
                        <h:panelGrid columns="15"  >
                            <h:outputLabel value="OPD CREDIT BIll PAYMENT" />
                            <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />
                            <p:selectOneMenu   id="cmbPs" value="#{cashRecieveBillController.current.paymentMethod}">                                                                     
                                <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"/>
                                <p:ajax process="cmbPs" update="creditCard cheque slip" event="change" />
                            </p:selectOneMenu>

                            <p:inputText value="#{cashRecieveBillController.comment}" id="comment"/>
                            <p:watermark value="Comment" for="comment"/>

                            <h:panelGroup id="creditCard" style="display: #{cashRecieveBillController.current.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{cashRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{cashRecieveBillController.current.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{cashRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{cashRecieveBillController.current.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{cashRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <p:commandButton id="btnSettle" value="Settle" action="#{cashRecieveBillController.settleBill}"
                                             ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;" onclick="onSubmitButton();">
                            </p:commandButton>
                            <p:defaultCommand target="btnSettle"/>
                            <p:commandButton value="New Bill" ajax="false" action="#{cashRecieveBillController.prepareNewBill()}" onclick="onSubmitButton();" >
                            </p:commandButton>

                        </h:panelGrid>
                    </f:facet>
                    <p:panelGrid columns="2" style="min-width: 100%;">
                        <h:panelGroup>
                            <p:autoComplete widgetVar="aIx" id="acIx" 
                                            forceSelection="true" 
                                            value="#{cashRecieveBillController.currentBillItem.referenceBill}" 
                                            completeMethod="#{billController.completeOpdCreditBill}" 
                                            var="ix" itemLabel="#{ix.patient.person.name}"
                                            itemValue="#{ix}" size="30"  style="width: 400px;">
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Name"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.patient.person.name}"/>
                                </p:column>                                  
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Credit Company"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.creditCompany.name}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Date"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.createdAt}">
                                        <f:convertDateTime pattern="dd MM YYYY"/>
                                    </h:outputLabel>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Due Amount"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.netTotal+ix.vat +ix.paidAmount}" style="color: red;">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Paid Amount"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.paidAmount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputLabel value="Full Amount"/>
                                    </f:facet>
                                    <h:outputLabel value="#{ix.netTotal+ix.vat}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <f:ajax execute="@this" event="itemSelect" render="val" listener="#{cashRecieveBillController.selectBillListener()}"/>
                            </p:autoComplete>
                            <p:inputText autocomplete="off" id="val" value="#{cashRecieveBillController.currentBillItem.netValue}">
                                <f:convertNumber pattern="#,##0.00" />
                            </p:inputText>
                            <p:commandButton id="btnAddIx" value="Add" action="#{cashRecieveBillController.addToBill()}" ajax="false" onclick="onSubmitButton();"/>
                        </h:panelGroup>
                        <p:dataTable value="#{cashRecieveBillController.billItems}" rowIndexVar="rowIndex"   var="b" id="items">
                            <f:facet name="header">
                                <h:outputLabel value="Items For Billing"/>
                            </f:facet>                           
                            <p:column >  
                                <f:facet name="header">
                                    <h:outputLabel value="Bill No"/>                                    
                                </f:facet>                               
                                <p:outputLabel value="#{b.referenceBill.insId}"/>
                            </p:column>
                            <p:column headerText="Patient Name">
                                <p:outputLabel value="#{b.referenceBill.patient.person.name}"/>                               
                            </p:column>
                            <p:column headerText="Credit Company">     
                                <p:outputLabel value="#{b.referenceBill.creditCompany.name}" />                                
                            </p:column>
                            <p:column headerText="Net Total">
                                <h:outputLabel value="#{b.netValue}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </p:column>
                            <p:column headerText="Remove">
                                <p:commandButton ajax="false" action="#{cashRecieveBillController.remove(b)}" value="X" onclick="onSubmitButton();">
                                </p:commandButton>
                            </p:column>
                        </p:dataTable>


                    </p:panelGrid>
                    <p:panelGrid columns="2" style="min-width: 100%;">

                        <p:panelGrid  columns="2">
                            <p:outputLabel value="Net Total" />
                            <p:outputLabel id="tot" value="#{cashRecieveBillController.current.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </p:outputLabel>

                            <p:outputLabel value="Description"/>
                            <p:inputTextarea value="#{cashRecieveBillController.current.comments}"/>                                                         
                        </p:panelGrid>
                    </p:panelGrid>
                </p:panel>



                <p:panel rendered="#{cashRecieveBillController.printPreview}" >
                    <p:commandButton value="New Bill" ajax="false" action="#{cashRecieveBillController.prepareNewBill()}"  onclick="onSubmitButton();">
                    </p:commandButton>
                    <bi:insRecieve billController="#{cashRecieveBillController}"  bill="#{cashRecieveBillController.current}" dup="false"/>                       
                </p:panel>

            </h:form>
        </h:panelGroup>

    </ui:define>

</ui:composition>
